<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>现代化登录/注册</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
        @import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700;800&display=swap');

        :root {
            /* 主题颜色 */
            --primary: #4361ee;
            --primary-dark: #3a0ca3;
            --secondary: #f72585;
            --text: #212529;
            --text-light: #6c757d;
            --bg: #f8f9fa;
            --card-bg: #ffffff;
            --input-bg: #e9ecef;
            --border: #dee2e6;
            --shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
            --success: #4cc9f0;
            --error: #f72585;
            --social-bg: #ffffff;
            --social-hover: #f1f3f5;

            /* 尺寸和间距 */
            --border-radius: 12px;
            --transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
        }

        .dark-mode {
            --text: #f8f9fa;
            --text-light: #adb5bd;
            --bg: #121212;
            --card-bg: #1e1e1e;
            --input-bg: #2d2d2d;
            --border: #495057;
            --shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
            --social-bg: #2d2d2d;
            --social-hover: #3d3d3d;
        }

        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Poppins', 'Segoe UI', system-ui, -apple-system, sans-serif;
        }

        body {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            padding: 20px;
            transition: var(--transition);
        }

        /* 主容器 */
        .auth-container {
            position: relative;
            width: 900px;
            max-width: 100%;
            height: 580px;
            background-color: var(--card-bg);
            border-radius: var(--border-radius);
            box-shadow: var(--shadow);
            overflow: hidden;
            transition: var(--transition);
        }

        .forms-container {
            position: absolute;
            top: 0;
            height: 100%;
            transition: var(--transition);
            width: 100%;
        }

        /* 表单区域 */
        .form-container {
            position: absolute;
            top: 0;
            height: 100%;
            padding: 40px;
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            text-align: center;
            transition: var(--transition);
            width: 50%;
        }

        .sign-in-container {
            left: 0;
        }

        .sign-up-container {
            left: 0;
            width: 50%;
            opacity: 0;
            z-index: 1;
        }

        .container.right-panel-active .sign-up-container {
            transform: translateX(100%);
            opacity: 1;
            z-index: 5;
        }

        .container.right-panel-active .sign-in-container {
            transform: translateX(100%);
        }

        /* 覆盖层容器 */
        .overlay-container {
            position: absolute;
            top: 0;
            left: 50%;
            width: 50%;
            height: 100%;
            overflow: hidden;
            transition: var(--transition);
            z-index: 10;
        }

        .container.right-panel-active .overlay-container {
            transform: translateX(-100%);
        }

        /* 覆盖层 */
        .overlay {
            background: linear-gradient(135deg, var(--primary), var(--primary-dark));
            background-size: cover;
            background-position: 0 0;
            color: #ffffff;
            position: relative;
            left: -100%;
            height: 100%;
            width: 200%;
            transform: translateX(0);
            transition: var(--transition);
        }

        .container.right-panel-active .overlay {
            transform: translateX(50%);
        }

        /* 覆盖面板 */
        .overlay-panel {
            position: absolute;
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            padding: 0 40px;
            text-align: center;
            top: 0;
            height: 100%;
            width: 50%;
            transform: translateX(0);
            transition: var(--transition);
        }

        .overlay-left {
            transform: translateX(-20%);
        }

        .container.right-panel-active .overlay-left {
            transform: translateX(0);
        }

        .overlay-right {
            right: 0;
            transform: translateX(0);
        }

        .container.right-panel-active .overlay-right {
            transform: translateX(20%);
        }

        /* 内容样式 */
        h1 {
            font-weight: 700;
            margin-bottom: 15px;
        }

        .title {
            font-size: 2.2rem;
            margin-bottom: 10px;
        }

        .description {
            font-size: 1rem;
            font-weight: 400;
            line-height: 1.6;
            color: rgba(255, 255, 255, 0.9);
            margin-bottom: 30px;
        }

        .form-title {
            font-size: 1.8rem;
            margin-bottom: 10px;
        }

        .form-description {
            font-size: 0.95rem;
            color: var(--text-light);
            margin-bottom: 25px;
        }

        .dark-mode .form-description {
            color: var(--text-light);
        }

        /* 表单元素 */
        .social-container {
            margin: 25px 0;
            display: flex;
            justify-content: center;
            gap: 15px;
        }

        .social-icon {
            width: 46px;
            height: 46px;
            border-radius: 50%;
            display: flex;
            justify-content: center;
            align-items: center;
            background-color: var(--social-bg);
            color: var(--primary);
            font-size: 1.1rem;
            cursor: pointer;
            transition: var(--transition);
            border: 1px solid var(--border);
        }

        .dark-mode .social-icon {
            border-color: var(--border);
        }

        .social-icon:hover {
            background-color: var(--social-hover);
            transform: translateY(-3px);
        }

        .divider-text {
            font-size: 0.9rem;
            color: var(--text-light);
            margin: 15px 0;
            position: relative;
        }

        .dark-mode .divider-text {
            color: var(--text-light);
        }

        .form-group {
            width: 100%;
            margin-bottom: 20px;
            position: relative;
        }

        .form-control {
            width: 100%;
            padding: 15px 20px 15px 45px;
            border: 2px solid var(--border);
            border-radius: var(--border-radius);
            background-color: var(--input-bg);
            color: var(--text);
            font-size: 1rem;
            transition: var(--transition);
        }

        .dark-mode .form-control {
            border-color: var(--border);
        }

        .form-control:focus {
            outline: none;
            border-color: var(--primary);
            box-shadow: 0 0 0 3px rgba(67, 97, 238, 0.2);
        }

        .input-icon {
            position: absolute;
            left: 15px;
            top: 50%;
            transform: translateY(-50%);
            color: var(--text-light);
            transition: var(--transition);
        }

        .form-control:focus + .input-icon {
            color: var(--primary);
        }

        .password-toggle {
            position: absolute;
            right: 15px;
            top: 50%;
            transform: translateY(-50%);
            background: none;
            border: none;
            color: var(--text-light);
            cursor: pointer;
            padding: 5px;
            border-radius: 4px;
            transition: var(--transition);
            opacity: 0;
            visibility: hidden;
        }

        .password-toggle.show {
            opacity: 1;
            visibility: visible;
        }

        .password-toggle:hover {
            color: var(--primary);
            background: rgba(67, 97, 238, 0.1);
        }

        .options {
            display: flex;
            justify-content: space-between;
            align-items: center;
            width: 100%;
            margin-bottom: 25px;
            font-size: 0.9rem;
        }

        .checkbox-group {
            display: flex;
            align-items: center;
        }

        .checkbox-group input {
            margin-right: 8px;
            accent-color: var(--primary);
        }

        .link-btn {
            color: var(--primary);
            text-decoration: none;
            font-weight: 500;
            transition: var(--transition);
            background: none;
            border: none;
            cursor: pointer;
            padding: 0;
            font-size: inherit;
        }

        .link-btn:hover {
            text-decoration: underline;
        }

        /* 按钮 */
        .btn {
            border-radius: 50px;
            border: 1px solid var(--primary);
            background-color: var(--primary);
            color: #ffffff;
            font-size: 1rem;
            font-weight: 600;
            padding: 14px 45px;
            letter-spacing: 1px;
            text-transform: uppercase;
            transition: var(--transition);
            cursor: pointer;
            width: 100%;
            margin-top: 10px;
        }

        .btn:hover {
            background-color: var(--primary-dark);
            border-color: var(--primary-dark);
            transform: translateY(-3px);
            box-shadow: 0 10px 20px rgba(67, 97, 238, 0.2);
        }

        .btn:active {
            transform: scale(0.98);
        }

        .btn:focus {
            outline: none;
        }

        .ghost {
            background-color: transparent;
            border-color: #ffffff;
        }

        .ghost:hover {
            background-color: #ffffff;
            color: var(--primary-dark);
        }

        /* 响应式 */
        @media (max-width: 768px) {
            .auth-container {
                height: auto;
                min-height: 100vh;
                border-radius: 0;
            }

            .form-container {
                position: relative;
                width: 100%;
                padding: 30px 20px;
            }

            .sign-in-container {
                transform: translateX(0) !important;
            }

            .sign-up-container {
                transform: translateX(0) !important;
                display: none;
            }

            .container.right-panel-active .sign-in-container {
                display: none;
            }

            .container.right-panel-active .sign-up-container {
                display: flex;
            }

            .overlay-container {
                display: none;
            }
        }

        /* 加载动画 */
        .loading {
            display: inline-block;
            width: 20px;
            height: 20px;
            border: 3px solid rgba(255, 255, 255, 0.3);
            border-radius: 50%;
            border-top-color: white;
            animation: spin 1s ease-in-out infinite;
            margin-right: 10px;
        }

        @keyframes spin {
            to {
                transform: rotate(360deg);
            }
        }

        /* 表单验证状态 */
        .form-group.error .form-control {
            border-color: var(--error);
            background-color: rgba(247, 37, 133, 0.05);
        }

        .form-group.error .input-icon {
            color: var(--error);
        }

        .error-message {
            color: var(--error);
            font-size: 0.8rem;
            text-align: left;
            margin-top: 5px;
            display: none;
        }

        .form-group.error .error-message {
            display: block;
        }

        .form-group.success .form-control {
            border-color: var(--success);
            background-color: rgba(76, 201, 240, 0.05);
        }

        .form-group.success .input-icon {
            color: var(--success);
        }
    </style>
</head>
<body>
<!-- 登录注册容器 -->
<div class="auth-container container" id="container">
    <div class="forms-container">
        <!-- 登录表单 -->
        <div class="form-container sign-in-container">
            <form id="login-form">
                <h1 class="form-title">欢迎回来</h1>
                <p class="form-description">请输入您的凭据以登录您的帐户</p>
                <div class="social-container">
                    <div class="social-icon">
                        <i class="fab fa-weixin"></i>
                    </div>
                    <div class="social-icon">
                        <i class="fab fa-qq"></i>
                    </div>
                    <div class="social-icon">
                        <i class="fab fa-weibo"></i>
                    </div>
                </div>
                <span class="divider-text">或使用您的邮箱账户</span>
                <div class="form-group">
                    <div class="input-wrapper">
                        <input type="email" id="login-email" class="form-control" placeholder="电子邮箱" required />
                        <i class="fas fa-envelope input-icon"></i>
                    </div>
                    <div class="error-message">请输入有效的邮箱地址</div>
                </div>
                <div class="form-group">
                    <div class="input-wrapper">
                        <input type="password" id="login-password" class="form-control" placeholder="密码" required />
                        <i class="fas fa-lock input-icon"></i>
                        <button type="button" class="password-toggle" id="login-password-toggle">
                            <i class="fas fa-eye"></i>
                        </button>
                    </div>
                    <div class="error-message">密码至少需要6位字符</div>
                </div>
                <div class="options">
                    <div class="checkbox-group">
                        <input type="checkbox" id="remember" />
                        <label for="remember">记住我</label>
                    </div>
                    <button type="button" class="link-btn" id="forgot-password-btn">忘记密码?</button>
                </div>
                <button type="submit" class="btn">登录</button>
            </form>
        </div>

        <!-- 注册表单 -->
        <div class="form-container sign-up-container">
            <form id="register-form">
                <h1 class="form-title">创建账号</h1>
                <p class="form-description">填写以下信息创建新帐户</p>
                <div class="social-container">
                    <div class="social-icon">
                        <i class="fab fa-weixin"></i>
                    </div>
                    <div class="social-icon">
                        <i class="fab fa-qq"></i>
                    </div>
                    <div class="social-icon">
                        <i class="fab fa-weibo"></i>
                    </div>
                </div>
                <span class="divider-text">或使用您的邮箱注册</span>
                <div class="form-group">
                    <div class="input-wrapper">
                        <input type="text" id="reg-name" class="form-control" placeholder="用户名" required />
                        <i class="fas fa-user input-icon"></i>
                    </div>
                    <div class="error-message">用户名至少需要3个字符</div>
                </div>
                <div class="form-group">
                    <div class="input-wrapper">
                        <input type="email" id="reg-email" class="form-control" placeholder="电子邮箱" required />
                        <i class="fas fa-envelope input-icon"></i>
                    </div>
                    <div class="error-message">请输入有效的邮箱地址</div>
                </div>
                <div class="form-group">
                    <div class="input-wrapper">
                        <input type="password" id="reg-password" class="form-control" placeholder="密码 (至少8位)" required />
                        <i class="fas fa-lock input-icon"></i>
                        <button type="button" class="password-toggle" id="reg-password-toggle">
                            <i class="fas fa-eye"></i>
                        </button>
                    </div>
                    <div class="error-message">密码至少需要8位字符</div>
                </div>
                <div class="form-group">
                    <div class="input-wrapper">
                        <input type="password" id="reg-confirm-password" class="form-control" placeholder="确认密码" required />
                        <i class="fas fa-lock input-icon"></i>
                    </div>
                    <div class="error-message">两次输入的密码不一致</div>
                </div>
                <button type="submit" class="btn">注册</button>
            </form>
        </div>
    </div>

    <!-- 覆盖层 -->
    <div class="overlay-container">
        <div class="overlay">
            <div class="overlay-panel overlay-left">
                <h1 class="title">已有账号?</h1>
                <p class="description">立即登录您的账号，继续您的旅程</p>
                <button class="ghost btn" id="signIn">登录</button>
            </div>
            <div class="overlay-panel overlay-right">
                <h1 class="title">新用户?</h1>
                <p class="description">注册账号，开启您的个性化体验之旅</p>
                <button class="ghost btn" id="signUp">注册</button>
            </div>
        </div>
    </div>
</div>

<script>
    document.addEventListener('DOMContentLoaded', function () {
        // DOM 元素
        const signUpButton = document.getElementById('signUp');
        const signInButton = document.getElementById('signIn');
        const container = document.getElementById('container');
        const loginForm = document.getElementById('login-form');
        const registerForm = document.getElementById('register-form');
        const forgotPasswordBtn = document.getElementById('forgot-password-btn');

        // 密码切换按钮
        const loginPasswordInput = document.getElementById('login-password');
        const loginPasswordToggle = document.getElementById('login-password-toggle');
        const regPasswordInput = document.getElementById('reg-password');
        const regPasswordToggle = document.getElementById('reg-password-toggle');

        // 切换事件
        signUpButton.addEventListener('click', () => {
            container.classList.add("right-panel-active");
        });

        signInButton.addEventListener('click', () => {
            container.classList.remove("right-panel-active");
        });

        // 密码显示/隐藏 (登录)
        loginPasswordInput.addEventListener('input', function () {
            if (this.value.length > 0) {
                loginPasswordToggle.classList.add('show');
            } else {
                loginPasswordToggle.classList.remove('show');
                if (this.type === 'text') {
                    this.type = 'password';
                    const icon = loginPasswordToggle.querySelector('i');
                    icon.classList.remove('fa-eye-slash');
                    icon.classList.add('fa-eye');
                }
            }
        });

        loginPasswordToggle.addEventListener('click', function () {
            const icon = this.querySelector('i');
            if (loginPasswordInput.type === 'password') {
                loginPasswordInput.type = 'text';
                icon.classList.remove('fa-eye');
                icon.classList.add('fa-eye-slash');
            } else {
                loginPasswordInput.type = 'password';
                icon.classList.remove('fa-eye-slash');
                icon.classList.add('fa-eye');
            }
            this.style.transform = 'translateY(-50%) scale(0.9)';
            setTimeout(() => {
                this.style.transform = 'translateY(-50%) scale(1)';
            }, 150);
        });

        // 密码显示/隐藏 (注册)
        regPasswordInput.addEventListener('input', function () {
            if (this.value.length > 0) {
                regPasswordToggle.classList.add('show');
            } else {
                regPasswordToggle.classList.remove('show');
                if (this.type === 'text') {
                    this.type = 'password';
                    const icon = regPasswordToggle.querySelector('i');
                    icon.classList.remove('fa-eye-slash');
                    icon.classList.add('fa-eye');
                }
            }
        });

        regPasswordToggle.addEventListener('click', function () {
            const icon = this.querySelector('i');
            if (regPasswordInput.type === 'password') {
                regPasswordInput.type = 'text';
                icon.classList.remove('fa-eye');
                icon.classList.add('fa-eye-slash');
            } else {
                regPasswordInput.type = 'password';
                icon.classList.remove('fa-eye-slash');
                icon.classList.add('fa-eye');
            }
            this.style.transform = 'translateY(-50%) scale(0.9)';
            setTimeout(() => {
                this.style.transform = 'translateY(-50%) scale(1)';
            }, 150);
        });

        // 忘记密码
        forgotPasswordBtn.addEventListener('click', () => {
            alert('密码重置邮件已发送到您的邮箱！');
        });

        // 表单验证辅助函数
        function validateEmail(email) {
            const re = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
            return re.test(email);
        }

        function setFieldStatus(fieldId, isValid, message = '') {
            const fieldGroup = document.querySelector(`#${fieldId}`).closest('.form-group');
            const errorMessage = fieldGroup.querySelector('.error-message');
            fieldGroup.classList.remove('error', 'success');
            if (isValid === false) {
                fieldGroup.classList.add('error');
                errorMessage.textContent = message;
            } else if (isValid === true) {
                fieldGroup.classList.add('success');
            }
        }

        // 登录表单验证
        document.getElementById('login-email').addEventListener('blur', function () {
            const isValid = validateEmail(this.value);
            setFieldStatus('login-email', isValid, '请输入有效的邮箱地址');
        });

        document.getElementById('login-password').addEventListener('blur', function () {
            const isValid = this.value.length >= 6;
            setFieldStatus('login-password', isValid, '密码至少需要6位字符');
        });

        // 注册表单验证
        document.getElementById('reg-name').addEventListener('blur', function () {
            const isValid = this.value.length >= 3;
            setFieldStatus('reg-name', isValid, '用户名至少需要3个字符');
        });

        document.getElementById('reg-email').addEventListener('blur', function () {
            const isValid = validateEmail(this.value);
            setFieldStatus('reg-email', isValid, '请输入有效的邮箱地址');
        });

        document.getElementById('reg-password').addEventListener('blur', function () {
            const isValid = this.value.length >= 8;
            setFieldStatus('reg-password', isValid, '密码至少需要8位字符');
        });

        document.getElementById('reg-confirm-password').addEventListener('blur', function () {
            const password = document.getElementById('reg-password').value;
            const isValid = this.value === password && this.value.length > 0;
            setFieldStatus('reg-confirm-password', isValid, '两次输入的密码不一致');
        });

        // 表单提交处理
        loginForm.addEventListener('submit', function (e) {
            e.preventDefault();
            const email = document.getElementById('login-email').value;
            const password = document.getElementById('login-password').value;

            const isEmailValid = validateEmail(email);
            const isPasswordValid = password.length >= 6;

            setFieldStatus('login-email', isEmailValid, '请输入有效的邮箱地址');
            setFieldStatus('login-password', isPasswordValid, '密码至少需要6位字符');

            if (isEmailValid && isPasswordValid) {
                const btn = this.querySelector('.btn');
                const originalText = btn.innerHTML;
                btn.innerHTML = '<span class="loading"></span>登录中...';
                btn.disabled = true;

                // 模拟登录请求
                setTimeout(() => {
                    alert(`登录成功！\n邮箱: ${email}`);
                    btn.innerHTML = originalText;
                    btn.disabled = false;
                }, 1500);
            }
        });

        registerForm.addEventListener('submit', function (e) {
            e.preventDefault();
            const name = document.getElementById('reg-name').value;
            const email = document.getElementById('reg-email').value;
            const password = document.getElementById('reg-password').value;
            const confirmPassword = document.getElementById('reg-confirm-password').value;

            const isNameValid = name.length >= 3;
            const isEmailValid = validateEmail(email);
            const isPasswordValid = password.length >= 8;
            const isConfirmPasswordValid = password === confirmPassword && confirmPassword.length > 0;

            setFieldStatus('reg-name', isNameValid, '用户名至少需要3个字符');
            setFieldStatus('reg-email', isEmailValid, '请输入有效的邮箱地址');
            setFieldStatus('reg-password', isPasswordValid, '密码至少需要8位字符');
            setFieldStatus('reg-confirm-password', isConfirmPasswordValid, '两次输入的密码不一致');

            if (isNameValid && isEmailValid && isPasswordValid && isConfirmPasswordValid) {
                const btn = this.querySelector('.btn');
                const originalText = btn.innerHTML;
                btn.innerHTML = '<span class="loading"></span>注册中...';
                btn.disabled = true;

                // 模拟注册请求
                setTimeout(() => {
                    alert(`注册成功！\n用户名: ${name}\n邮箱: ${email}`);
                    btn.innerHTML = originalText;
                    btn.disabled = false;
                    // 注册成功后自动切换到登录
                    container.classList.remove("right-panel-active");
                }, 1500);
            }
        });

    });
</script>
</body>
</html>